package vn.vfriends.mcms.site.service.impl.exceptions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;

/**
 *
 * @author tuan@vfriends.vn
 */
public class ViolationException extends Exception {

    private List<String> messages = new ArrayList<String> ();
    
    public <T> ViolationException(Set<ConstraintViolation<T>> violations) {
        if (violations.size() > 0) {
            Iterator<ConstraintViolation<T>> it = violations.iterator();
            while (it.hasNext()) {
                ConstraintViolation violation = it.next();
                messages.add(violation.getMessage());
            }
        }
    }

    public List<String> getMessages() {
        return messages;
    }

    @Override
    public String toString() {
        return "ViolationException{" + "messages=" + messages + '}';
    }
}
